package com.dksidana.java.pool;

public class ObjectTimestampPair<K> {
    K object;
    long timestamp;

    public ObjectTimestampPair(K val) {
        this(val, System.currentTimeMillis());
    }

    public ObjectTimestampPair(K val, long time) {
        object = val;
        timestamp = time;
    }

    public K getObject() {
		return object;
	}

	public void setObject(K object) {
		this.object = object;
	}

	public long getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(long timestamp) {
		this.timestamp = timestamp;
	}

	public String toString() {
        return object + ";" + timestamp;
    }
    
    
    public int compareTo(ObjectTimestampPair<K> other) {
        final long tstampdiff = this.timestamp - other.timestamp;
        if (tstampdiff == 0) {
            // make sure the natural ordering is consistent with equals
            // see java.lang.Comparable Javadocs
            return System.identityHashCode(this) - System.identityHashCode(other);
        } else {
            // handle int overflow
            return (int)Math.min(Math.max(tstampdiff, Integer.MIN_VALUE), Integer.MAX_VALUE);
        }
    }

}
